﻿using StudySystem.MainLogic;
using StudySystem.MainLogic.FormControl;
using StudySystem.MainLogic.Items;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace StudySystem.Windows
{
    public partial class FormSubName : Form
    {
        private ClassSubject subject;
        private Subject s;
        public FormSubName()
        {
            InitializeComponent();
        }
        public FormSubName(ClassSubject subject,Subject s)
        {
            InitializeComponent();
            this.subject = subject;
            this.s = s;
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (txtNewName.Text != "" && ClassSubject.CheckSubName(txtNewName.Text,UserManagement.subjects))
            {
                subject.ModifySubName(txtNewName.Text);
                DialogResult dr = MessageBox.Show("新课程名更改成功！");
                this.Hide();
                if(dr == DialogResult.OK)
                {
                    FormSubControl.ModifySubName(s, txtNewName.Text);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("新课程名称重复或为空！");
            }
        }

        private void FormSubName_Load(object sender, EventArgs e)
        {
            lblOldName.Text = subject.SubjectName;
        }
    }
}
